//
// Created by wk on 2024/1/2.
//

#ifndef FILEENCRYPTUTILS_ENCRYPTINTERFACE_H
#define FILEENCRYPTUTILS_ENCRYPTINTERFACE_H

#include <fstream>

#include <cinttypes>
#include <iostream>
#include <ios>
#include <stdio.h>

typedef uint32_t DWORD;
typedef unsigned char BYTE;
typedef BYTE *LPBYTE;


typedef int off32_t;
typedef unsigned int off32_u;
typedef unsigned off8_t;
typedef unsigned char off8_u;
typedef int64_t off64_t;

typedef uint32_t DWORD;
typedef unsigned char BYTE;

typedef BYTE *LPBYTE;
#pragma pack(push, 1)
struct XG_HEAD {
    DWORD EncrySolution;   //加密方案，1:MP3   2:H.265
    BYTE VideoType[4];    //歌曲类型：XMP3 XM4A XMPG XMP4 XMOV XMKV（H265）
    DWORD KeyNumber;       //秘钥编号：0 - 16
    BYTE nFlags[4];       //唯一标示 星光：XGDX
    DWORD EncryTime;       //加密时间
    DWORD Res1;            //预留
    DWORD Res2;            //预留
    DWORD key;             //秘钥，用于加密前面的数据
};
#pragma pack(pop)


enum EncryptType {
    EncryptType_None = 0,       //未加密
    EncryptType_FET_MOV = 1,    //mov(h264+mp2)
    EncryptType_OLD_MPEG = 2,   //mpeg(早期)(mpeg2+aac)
    EncryptType_MPEG = 4,       //mpeg(mpeg2+aac)
    EncryptType_H265 = 6,       //H265(HEVC + mp2)
    EncryptType_XG = 10,   //星光新算法
};





class IDecryptType {
public:
    virtual ~IDecryptType() {

    }

    virtual bool isEncryptType(FILE *inputFile) = 0;

    EncryptType getEncryptType() {
        return mEncryptType;
    }

protected:
    EncryptType mEncryptType = EncryptType_None;
};



class AutoCloseFile {
public:
    AutoCloseFile(FILE *input_file) {

        this->input_file = input_file;
    }

    ~AutoCloseFile() {
        if (this->input_file) {
            fclose(this->input_file);
            this->input_file = nullptr;
        }
    }

private:
    FILE *input_file = nullptr;
};


#endif //FILEENCRYPTUTILS_ENCRYPTINTERFACE_H
